<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>移动端优化篇 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="移动端,优化,">
  

  <meta name="description" content="一、概述 PC优化手段在Mobile侧同样适用 在Mobile侧我们提出三秒种渲染完成首屏指标 基于第二点，首屏加载3秒完成或使用Loading 基于联通3G网络平均338KB/s(2.71Mb/s），所以首屏资源不应超过1014KB Mobile侧因手机配置原因，除加载外渲染速度也是优化重点 基于第五点，要合理处理代码减少渲染损耗 基于第二、第五点，所有影响首屏加载和渲染的代码应在处理逻辑中后">
<meta name="keywords" content="移动端,优化">
<meta property="og:type" content="article">
<meta property="og:title" content="移动端优化篇">
<meta property="og:url" content="http://blog.poetries.top/2018/11/20/mobile-opitize/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、概述 PC优化手段在Mobile侧同样适用 在Mobile侧我们提出三秒种渲染完成首屏指标 基于第二点，首屏加载3秒完成或使用Loading 基于联通3G网络平均338KB/s(2.71Mb/s），所以首屏资源不应超过1014KB Mobile侧因手机配置原因，除加载外渲染速度也是优化重点 基于第五点，要合理处理代码减少渲染损耗 基于第二、第五点，所有影响首屏加载和渲染的代码应在处理逻辑中后">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://image-static.segmentfault.com/462/322/462322984-553e3da07b565_articlex">
<meta property="og:updated_time" content="2020-08-15T04:25:31.926Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="移动端优化篇">
<meta name="twitter:description" content="一、概述 PC优化手段在Mobile侧同样适用 在Mobile侧我们提出三秒种渲染完成首屏指标 基于第二点，首屏加载3秒完成或使用Loading 基于联通3G网络平均338KB/s(2.71Mb/s），所以首屏资源不应超过1014KB Mobile侧因手机配置原因，除加载外渲染速度也是优化重点 基于第五点，要合理处理代码减少渲染损耗 基于第二、第五点，所有影响首屏加载和渲染的代码应在处理逻辑中后">
<meta name="twitter:image" content="https://image-static.segmentfault.com/462/322/462322984-553e3da07b565_articlex">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、概述"><span class="toc-text">一、概述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、加载优化"><span class="toc-text">二、加载优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-缓存"><span class="toc-text">2.1 缓存</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-压缩HTML、CSS、JavaScript"><span class="toc-text">2.2 压缩HTML、CSS、JavaScript</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-无阻塞"><span class="toc-text">2.3 无阻塞</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-使用首屏加载"><span class="toc-text">2.4 使用首屏加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-按需加载"><span class="toc-text">2.5 按需加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-预加载"><span class="toc-text">2.6 预加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-7-压缩图片"><span class="toc-text">2.7 压缩图片</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-8-减少Cookie"><span class="toc-text">2.8 减少Cookie</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-9-避免重定向"><span class="toc-text">2.9 避免重定向</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-10-异步加载第三方资源"><span class="toc-text">2.10 异步加载第三方资源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-11-减少HTTP请求"><span class="toc-text">2.11 减少HTTP请求</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、脚本执行优化"><span class="toc-text">三、脚本执行优化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、CSS优化"><span class="toc-text">四、CSS优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-css3过渡动画开启硬件加速"><span class="toc-text">4.1 css3过渡动画开启硬件加速</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-避免CSS表达式"><span class="toc-text">4.2 避免CSS表达式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-3-不滥用Float"><span class="toc-text">4.3 不滥用Float</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-4-值为0时不需要任何单位"><span class="toc-text">4.4 值为0时不需要任何单位</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、JavaScript执行优化"><span class="toc-text">五、JavaScript执行优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-减少重绘和回流"><span class="toc-text">5.1 减少重绘和回流</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-TOUCH事件优化"><span class="toc-text">5.2 TOUCH事件优化</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#六、渲染优化"><span class="toc-text">六、渲染优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-HTML使用Viewport"><span class="toc-text">6.1 HTML使用Viewport</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-2-动画优化"><span class="toc-text">6.2 动画优化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-4-高频事件优化"><span class="toc-text">6.4 高频事件优化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-5-GPU加速"><span class="toc-text">6.5 GPU加速</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#七、参考"><span class="toc-text">七、参考</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-mobile-opitize" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">移动端优化篇</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2018.11.20</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.6k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 5分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <p><img src="https://image-static.segmentfault.com/462/322/462322984-553e3da07b565_articlex" alt></p>
<h2 id="一、概述"><a href="#一、概述" class="headerlink" title="一、概述"></a>一、概述</h2><ul>
<li><code>PC</code>优化手段在<code>Mobile</code>侧同样适用</li>
<li>在<code>Mobile</code>侧我们提出三秒种渲染完成首屏指标</li>
<li>基于第二点，首屏加载<code>3</code>秒完成或使用<code>Loading</code></li>
<li>基于联通3G网络平均<code>338KB/s(2.71Mb/s</code>），所以首屏资源不应超过<code>1014KB</code></li>
<li><code>Mobile</code>侧因手机配置原因，除加载外渲染速度也是优化重点</li>
<li>基于第五点，要合理处理代码减少渲染损耗</li>
<li>基于第二、第五点，所有影响首屏加载和渲染的代码应在处理逻辑中后置</li>
<li>加载完成后用户交互使用时也需注意性能</li>
</ul>
<h2 id="二、加载优化"><a href="#二、加载优化" class="headerlink" title="二、加载优化"></a>二、加载优化</h2><blockquote>
<p>加载过程是最为耗时的过程，可能会占到总耗时的<code>80%</code>时间，因此是优化的重点</p>
</blockquote>
<h3 id="2-1-缓存"><a href="#2-1-缓存" class="headerlink" title="2.1 缓存"></a>2.1 缓存</h3><blockquote>
<p>使用缓存可以减少向服务器的请求数，节省加载时间，所以所有静态资源都要在服务器端设置缓存，并且尽量使用长<code>Cache</code>（长<code>Cache</code>资源的更新可使用时间戳）</p>
</blockquote>
<h3 id="2-2-压缩HTML、CSS、JavaScript"><a href="#2-2-压缩HTML、CSS、JavaScript" class="headerlink" title="2.2 压缩HTML、CSS、JavaScript"></a>2.2 压缩HTML、CSS、JavaScript</h3><blockquote>
<p>减少资源大小可以加快网页显示速度，所以要对<code>HTML</code>、<code>CSS</code>、<code>JavaScript</code>等进行代码压缩，并在服务器端设置<code>GZip</code></p>
</blockquote>
<ul>
<li>a） 压缩（例如，多余的空格、换行符和缩进）</li>
<li>b） 启用<code>GZip</code></li>
</ul>
<h3 id="2-3-无阻塞"><a href="#2-3-无阻塞" class="headerlink" title="2.3 无阻塞"></a>2.3 无阻塞</h3><blockquote>
<p>写在<code>HTML</code>头部的<code>JavaScript</code>（无异步），和写在<code>HTML</code>标签中的<code>Style</code>会阻塞页面的渲染，因此<code>CSS</code>放在页面头部并使用<code>Link</code>方式引入，避免在<code>HTML</code>标签中写<code>Style</code>，<code>JavaScript</code>放在页面尾部或使用异步方式加载</p>
</blockquote>
<h3 id="2-4-使用首屏加载"><a href="#2-4-使用首屏加载" class="headerlink" title="2.4 使用首屏加载"></a>2.4 使用首屏加载</h3><blockquote>
<p>首屏的快速显示，可以大大提升用户对页面速度的感知，因此应尽量针对首屏的快速显示做优化。</p>
</blockquote>
<h3 id="2-5-按需加载"><a href="#2-5-按需加载" class="headerlink" title="2.5 按需加载"></a>2.5 按需加载</h3><blockquote>
<p>将不影响首屏的资源和当前屏幕资源不用的资源放到用户需要时才加载，可以大大提升重要资源的显示速度和降低总体流量。</p>
</blockquote>
<p><strong>PS：按需加载会导致大量重绘，影响渲染性能</strong></p>
<ul>
<li>a） <code>LazyLoad</code></li>
<li>b） 滚屏加载</li>
<li>c） 通过<code>Media Query</code>加载</li>
</ul>
<h3 id="2-6-预加载"><a href="#2-6-预加载" class="headerlink" title="2.6 预加载"></a>2.6 预加载</h3><blockquote>
<p>大型重资源页面（如游戏）可使用增加<code>Loading</code>的方法，资源加载完成后再显示页面。但<code>Loading</code>时间过长，会造成用户流失。</p>
</blockquote>
<p>对用户行为分析，可以在当前页加载下一页资源，提升速度。</p>
<ul>
<li>a）可感知<code>Loading</code></li>
<li>b）不可感知的<code>Loading</code>（如提前加载下一页）</li>
</ul>
<h3 id="2-7-压缩图片"><a href="#2-7-压缩图片" class="headerlink" title="2.7 压缩图片"></a>2.7 压缩图片</h3><blockquote>
<p>图片是最占流量的资源，因此尽量避免使用他，使用时选择最合适的格式（实现需求的前提下，以大小判断），合适的大小，然后使用智图压缩，同时在代码中用<code>Srcset</code>来按需显示</p>
</blockquote>
<p><strong>PS：过度压缩图片大小影响图片显示效果</strong></p>
<ul>
<li>a）使用智图（ <a href="http://zhitu.tencent.com/" target="_blank" rel="noopener">http://zhitu.tencent.com/</a> ）</li>
<li>b）使用其它方式代替图片(1. 使用<code>CSS3</code> 2. 使用<code>SVG</code> 3. 使用<code>IconFont</code>）</li>
<li>c）使用<code>Srcset</code></li>
<li>d）选择合适的图片(1. <code>webP</code>优于<code>JPG</code>2. <code>PNG8</code>优于<code>GIF</code>）</li>
<li>e）选择合适的大小（1. 首次加载不大于<code>1014KB</code> 2. 不宽于<code>640</code>（基于手机屏幕一般宽度））</li>
</ul>
<h3 id="2-8-减少Cookie"><a href="#2-8-减少Cookie" class="headerlink" title="2.8 减少Cookie"></a>2.8 减少Cookie</h3><blockquote>
<p><code>Cookie</code>会影响加载速度，所以静态资源域名不使用<code>Cookie</code>。</p>
</blockquote>
<h3 id="2-9-避免重定向"><a href="#2-9-避免重定向" class="headerlink" title="2.9 避免重定向"></a>2.9 避免重定向</h3><p>重定向会影响加载速度，所以在服务器正确设置避免重定向。</p>
<h3 id="2-10-异步加载第三方资源"><a href="#2-10-异步加载第三方资源" class="headerlink" title="2.10 异步加载第三方资源"></a>2.10 异步加载第三方资源</h3><p>第三方资源不可控会影响页面的加载和显示，因此要异步加载第三方资源</p>
<h3 id="2-11-减少HTTP请求"><a href="#2-11-减少HTTP请求" class="headerlink" title="2.11 减少HTTP请求"></a>2.11 减少HTTP请求</h3><blockquote>
<p>因为手机浏览器同时响应请求为4个请求（<code>Android</code>支持4个，<code>iOS</code> 5后可支持6个），所以要尽量减少页面的请求数，首次加载同时请求数不能超过4个</p>
</blockquote>
<ul>
<li>a）合并<code>CSS</code>、<code>JavaScript</code></li>
<li>b）合并小图片，使用雪碧图</li>
</ul>
<h2 id="三、脚本执行优化"><a href="#三、脚本执行优化" class="headerlink" title="三、脚本执行优化"></a>三、脚本执行优化</h2><blockquote>
<p>脚本处理不当会阻塞页面加载、渲染，因此在使用时需当注意</p>
</blockquote>
<ul>
<li><code>CSS</code>写在头部，<code>JavaScript</code>写在尾部或异步</li>
<li>避免图片和<code>iFrame</code>等的空<code>Src</code>，空<code>Src</code>会重新加载当前页面，影响速度和效率。</li>
<li>尽量避免重设图片大小</li>
<li>重设图片大小是指在页面、<code>CSS</code>、J<code>avaScript</code>等中多次重置图片大小，多次重设图片大小会引发图片的多次重绘，影响性能</li>
<li>图片尽量避免使用<code>DataURL</code>，<code>DataURL</code>图片没有使用图片的压缩算法文件会变大，并且要解码后再渲染，加载慢耗时长</li>
</ul>
<h2 id="四、CSS优化"><a href="#四、CSS优化" class="headerlink" title="四、CSS优化"></a>四、CSS优化</h2><blockquote>
<p>尽量避免写在HTML标签中写<code>Style</code>属性</p>
</blockquote>
<h3 id="4-1-css3过渡动画开启硬件加速"><a href="#4-1-css3过渡动画开启硬件加速" class="headerlink" title="4.1 css3过渡动画开启硬件加速"></a>4.1 css3过渡动画开启硬件加速</h3><figure class="highlight css"><table><tr><td class="code"><pre><span class="line"><span class="selector-class">.translate3d</span>&#123;</span><br><span class="line">   <span class="attribute">-webkit-transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">   <span class="attribute">-moz-transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">   <span class="attribute">-ms-transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">   <span class="attribute">transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<h3 id="4-2-避免CSS表达式"><a href="#4-2-避免CSS表达式" class="headerlink" title="4.2 避免CSS表达式"></a>4.2 避免CSS表达式</h3><p>CSS表达式的执行需跳出CSS树的渲染，因此请避免CSS表达式。</p>
<h3 id="4-3-不滥用Float"><a href="#4-3-不滥用Float" class="headerlink" title="4.3 不滥用Float"></a>4.3 不滥用Float</h3><p>Float在渲染时计算量比较大，尽量减少使用</p>
<h3 id="4-4-值为0时不需要任何单位"><a href="#4-4-值为0时不需要任何单位" class="headerlink" title="4.4 值为0时不需要任何单位"></a>4.4 值为0时不需要任何单位</h3><p>为了浏览器的兼容性和性能，值为<code>0</code>时不要带单位</p>
<h2 id="五、JavaScript执行优化"><a href="#五、JavaScript执行优化" class="headerlink" title="五、JavaScript执行优化"></a>五、JavaScript执行优化</h2><h3 id="5-1-减少重绘和回流"><a href="#5-1-减少重绘和回流" class="headerlink" title="5.1 减少重绘和回流"></a>5.1 减少重绘和回流</h3><ul>
<li>避免不必要的Dom操作</li>
<li>尽量改变<code>Class</code>而不是<code>Style</code>，使用<code>classList</code>代替<code>className</code></li>
<li>避免使用<code>document.write</code></li>
<li>减少<code>drawImage</code></li>
</ul>
<h3 id="5-2-TOUCH事件优化"><a href="#5-2-TOUCH事件优化" class="headerlink" title="5.2 TOUCH事件优化"></a>5.2 TOUCH事件优化</h3><blockquote>
<p>使用<code>touchstart</code>、<code>touchend</code>代替<code>click</code>，因快影响速度快。但应注意<code>Touch</code>响应过快，易引发误操作</p>
</blockquote>
<h2 id="六、渲染优化"><a href="#六、渲染优化" class="headerlink" title="六、渲染优化"></a>六、渲染优化</h2><h3 id="6-1-HTML使用Viewport"><a href="#6-1-HTML使用Viewport" class="headerlink" title="6.1 HTML使用Viewport"></a>6.1 HTML使用Viewport</h3><p><strong>Viewport可以加速页面的渲染，请使用以下代码</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&lt;meta name=”viewport” content=”width=device-width, initial-scale=1″&gt;</span><br></pre></td></tr></table></figure>
<h3 id="6-2-动画优化"><a href="#6-2-动画优化" class="headerlink" title="6.2 动画优化"></a>6.2 动画优化</h3><ul>
<li>尽量使用<code>CSS3</code>动画</li>
<li>合理使用<code>requestAnimationFrame</code>动画代替<code>setTimeout</code></li>
<li>适当使用<code>Canvas</code>动画 <code>5</code>个元素以内使用<code>css</code>动画，<code>5</code>个以上使用<code>Canvas</code>动画（<code>iOS8</code>可使用<code>webGL</code>）</li>
</ul>
<h3 id="6-4-高频事件优化"><a href="#6-4-高频事件优化" class="headerlink" title="6.4 高频事件优化"></a>6.4 高频事件优化</h3><blockquote>
<p><code>Touchmove</code>、<code>Scroll</code> 事件可导致多次渲染</p>
</blockquote>
<ul>
<li>使用<code>requestAnimationFrame</code>监听帧变化，使得在正确的时间进行渲染</li>
<li>增加响应变化的时间间隔，减少重绘次数</li>
</ul>
<h3 id="6-5-GPU加速"><a href="#6-5-GPU加速" class="headerlink" title="6.5 GPU加速"></a>6.5 GPU加速</h3><blockquote>
<p><code>CSS</code>中以下属性（<code>CSS3 transitions</code>、<code>CSS3 3D transforms</code>、<code>Opacity</code>、<code>Canvas</code>、<code>WebGL</code>、<code>Video</code>）来触发<code>GPU</code>渲染，请合理使用</p>
</blockquote>
<h2 id="七、参考"><a href="#七、参考" class="headerlink" title="七、参考"></a>七、参考</h2><ul>
<li><a href="https://www.cnblogs.com/yexiaochai/p/4219523.html" target="_blank" rel="noopener">浅谈移动前端的最佳实践-叶小钗</a></li>
</ul>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2018/11/20/react-fiber/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2018/11/20/hexo-comment/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
